export default function todoReducer(state, action) {
  switch (action.type) {
    case 'ADD':
      return [...state, action.todo]

    case 'DEL':
      return state.filter((item) => item.id != action.id)

    case 'EDIT':
      const index = state.findIndex(item => item.id == action.payload.id); // 返回下标
      const newTodoList = [...state];
      newTodoList.splice(index, 1, action.payload.todo)
      return newTodoList

    default:
      return state;
  }
}